package org.jz.gae.redbook.spb.server.controller;

import org.jz.gae.redbook.spb.server.helper.SpeciesHelper;
import org.jz.gae.redbook.spb.shared.SpeciesEntityView;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class SpeciesUtils
{
	public static void reflectEntityToView(
			Entity species,
			SpeciesEntityView newSpecies)
	{
		newSpecies.setSpeciesKey(KeyFactory.keyToString(species.getKey()));
		newSpecies.setSpeciesFamilyKey(KeyFactory.keyToString((Key)species.getProperty(SpeciesHelper.SPECIES_FAMILY_KEY)));
		newSpecies.setSpeciesLatName((String)species.getProperty(SpeciesHelper.SPECIES_LAT_NAME));
		newSpecies.setSpeciesRusName((String)species.getProperty(SpeciesHelper.SPECIES_RUS_NAME));
		newSpecies.setSpeciesNote((String)species.getProperty(SpeciesHelper.SPECIES_NOTE));
	}
	
    public static void reflectViewToEntity(
    		SpeciesEntityView _SpeciesToEdit,
			Entity species)
	{
		species.setProperty(SpeciesHelper.SPECIES_LAT_NAME, _SpeciesToEdit.getSpeciesLatName());
		species.setProperty(SpeciesHelper.SPECIES_RUS_NAME, _SpeciesToEdit.getSpeciesRusName());
        species.setProperty(SpeciesHelper.SPECIES_FAMILY_KEY, KeyFactory.stringToKey(_SpeciesToEdit.getSpeciesFamilyKey()));
		species.setProperty(SpeciesHelper.SPECIES_NOTE, _SpeciesToEdit.getSpeciesNote());
	}

}
